package com.hutianao.gqgl.job.service.impl;

import com.hutianao.gqgl.job.entity.SearchJobEntity;
import com.hutianao.gqgl.job.respository.JobDao;
import com.hutianao.gqgl.job.service.JobService;
import com.hutianao.gqgl.menu.entity.SearchMenuEntity;
import com.hutianao.gqgl.mybatis.entity.PtJobEntity;
import com.hutianao.gqgl.mybatis.entity.PtMenuEntity;
import com.hutianao.gqgl.mybatis.entity.PtPostEntity;
import com.hutianao.gqgl.mybatis.flexigrid.PaddingEntity;
import com.hutianao.gqgl.mybatis.flexigrid.PadingRstType;
import com.hutianao.gqgl.mybatis.ztree.ZtreeEntity;
import com.hutianao.gqgl.spring.control.BaseController;
import com.hutianao.gqgl.spring.tag.entity.DictTagEntity;
import com.hutianao.gqgl.spring.util.DataUitl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JobServiceImpl extends BaseController implements JobService {
    @Autowired
    private JobDao jobDao;

    @Override
    public List<ZtreeEntity> queryLeftOrganTree(){
        List<ZtreeEntity> list=jobDao.queryLeftOrganTree();

        return list;
    }
    @Override
    public PadingRstType<PtJobEntity> queryPostInfoListByOrgan(SearchJobEntity search, PaddingEntity padding){
        padding.deal(PtJobEntity.class);
        PadingRstType<PtJobEntity> padingRstType = new PadingRstType<>();
        padingRstType.setPage(padding.getPage());
        List<PtJobEntity> list =jobDao.queryPostInfoListByOrgan(search, padding);
        padingRstType.setRawRecords(list);
        Integer total =jobDao.queryPostInfoTotal(search);
        padingRstType.setTotal(total);
        padingRstType.putItems();

        return padingRstType;
    }
    @Override
    public PtJobEntity queryPostInfoById(@Param("dutyId") String dutyId){
        return jobDao.queryPostInfoById(dutyId);
    }
    @Override
    public List<DictTagEntity> queryRoleList(){
        return jobDao.queryRoleList();
    };
    @Override
    public List<DictTagEntity> queryOrganList(){
        return jobDao.queryOrganList();
    }



    @Override
    public void addPostInfo(PtJobEntity ptPostEntity){
        ptPostEntity.setDutyId(DataUitl.getUuid());
        jobDao.insertPostInfo(ptPostEntity);
    }

    @Override
    public void modifyPostInfo(PtJobEntity ptPostEntity){
        jobDao.modifyPostInfo(ptPostEntity);
    }

    @Override
    public void deletePostById(String dutyIdArray){
        String[] dutyIds=dutyIdArray.split(",");
        jobDao.deletePostById(dutyIds);
    }

    @Override
    public PadingRstType<PtMenuEntity> queryRoleMenuList(SearchMenuEntity search, PaddingEntity paddingEntity){
        paddingEntity.deal(PtMenuEntity .class);
        PadingRstType<PtMenuEntity> padingRstType=new PadingRstType<>();
        padingRstType.setPage(paddingEntity.getPage());
        List<PtMenuEntity> list=jobDao.queryRoleMenuList(search,paddingEntity);
        padingRstType.setRawRecords(list);
        Integer total =jobDao.queryRoleMenuTotal(search);
        padingRstType.setTotal(total);
        padingRstType.putItems();
        return padingRstType;
    }
}
